<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    
    
    
    public function createBlessing(){
        $from = I('from');
        $to = I('to');
        $content = I('content');
        if (empty($from)) $this->error('form参数错误！'); 
        if (empty($to)) $this->error('to参数错误！'); 
        if (empty($content)) $this->error('content参数错误！'); 
        
        $add = [
            'from'=>$from,
            'to'=>$to,
            'content'=>$content,
            'created_time'=>date('Y-m-d H:i:s'),
        ];
        $ret = M('Blessing')->add($add);
        if (!$ret) $this->error('数据添加失败');
        $this->ajaxReturn(['id'=>$ret]);
    }
    
    //获取祝福数据
    public function getBlessing(){
        $id = I('id');
        $data = M('Blessing')->where(['id'=>$id])->field('from,to,content')->find();
        if (!$data) $this->error('数据获取失败！');
        
        $this->ajaxReturn($data);
    }
}